﻿using Architecture.API.Application.TraceabilityCommand.ShoppingCommand;
using MediatR;
using Traceability.Domain;
using Traceability.Domain.Service.ShoppingServices;
using Traceability.Domain.TraceabilityDto;

namespace Architecture.API.Application.TraceabilityCommandHandler.ShoppingCommandHandler
{
    /// <summary>
    /// 商品添加命令处理器
    /// </summary>
    public class ShoppingCreateCommandHandler : IRequestHandler<ShoppingCreateCommand, int>
    {
        /// <summary>
        /// 商品服务
        /// </summary>
        protected readonly IShoppingService shoppingService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="shoppingService">商品服务</param>
        public ShoppingCreateCommandHandler(IShoppingService shoppingService)
        {
            this.shoppingService = shoppingService;
        }

        /// <summary>
        /// 添加商品信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(ShoppingCreateCommand request, CancellationToken cancellationToken)
        {
            return await shoppingService.AddShopping(new AddShoppingDto() {  ProductionBatch = request.ProductionBatch, QGPeriod = request.QGPeriod, ProductionLicense = request.ProductionLicense, ManufacturingEnterprise = request.ManufacturingEnterprise,PictureId=request.PictureId, ShoppingNameId = request.ShoppingNameId,PictureName=request.PictureName, CreatedBy = request.CreatedBy, CreatedDate = DateTime.Now });
        }
    }
}
